home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
8_3.lha
/
8_3
/
8_3_mail.c
< prev
next >
Wrap
Text File
|
1993-08-08
|
875b
|
43 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
/ Exercise 8.3
/ Read in a mail and address, with error checking
include <stream.h>
include <nameaddress.h>
nt read_name_and_address(ostream &out, istream &in,
name_and_address *val)
// set up flushing of the output stream
ostream *old = in.tie(&out);
// loop until we get something right
for ( ; ;
out << "Try again " <<
"(must be longer than one line)\n")
{
out << "Type a mail address, " <<
"followed by a blank line: ";
// read a line, including the newline
name_and_address ret;
in >> ret;
// check the value
if (!in)
{
in.tie(old);
return 0;
}
if (!ret.name[0] || !ret.name[1])
continue;
// return the value, restoring the old tie first
in.tie(old);
*val = ret;
return 1;
}